package com.hs.hlw.credit.system.common.enumeration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * LogicOperator
 * @author zhb
 * @date 2018/08/17
 */
public enum LogicOperator_DM {
    CASE_1((short) 1, "等于", " = ?", true),
    CASE_2((short) 2, "不等于", " <> ?", true),
    CASE_3((short) 3, "大于", " > ?", true),
    CASE_4((short) 4, "大于等于", " >= ?", true),
    CASE_5((short) 5, "小于", " < ?", true),
    CASE_6((short) 6, "小于等于", " <= ?", true),
    CASE_7((short) 7, "开头是", " like concat(?, '%')", true),
    CASE_8((short) 8, "结尾是", " like concat('%', ?)", true),
    CASE_9((short) 9, "包含", " like concat('%', ?, '%')", true),
    CASE_10((short) 10, "为空", " is null", false),
    CASE_11((short) 11, "不为空", " is not null", false);

    public Short code;
    public String value;
    public String detail;
    public Boolean editable;

    public static List<Map<String, Object>> getLogicOperatorsByDataType(FieldDataType_DM dataType) {
        List<Map<String, Object>> logicOperatorList = new ArrayList<>();
        switch (dataType) {
            case CHAR:
            case VARCHAR:
            case VARCHAR2:
            case TEXT:
            case CLOB:
                for (LogicOperator_DM enu : LogicOperator_DM.values()) {
                    if (!LogicOperator_DM.CASE_3.equals(enu) && !LogicOperator_DM.CASE_4.equals(enu) && !LogicOperator_DM.CASE_5.equals(enu) && !LogicOperator_DM.CASE_6.equals(enu)) {
                        logicOperatorList.add(enu.toMap());
                    }
                }
                break;
            case BIGINT:
            case DECIMAL:
            case INT:
            case TINYINT:
            case INTEGER:
            case NUMBER:
            case DOUBLE:
            case FLOAT:
            case DATE:
            case TIMESTAMP:
            case DATETIME:
                for (LogicOperator_DM enu : LogicOperator_DM.values()) {
                    if (!LogicOperator_DM.CASE_7.equals(enu) && !LogicOperator_DM.CASE_8.equals(enu) && !LogicOperator_DM.CASE_9.equals(enu)) {
                        logicOperatorList.add(enu.toMap());
                    }
                }
                break;
            default:
                break;
        }
        return logicOperatorList;
    }

    LogicOperator_DM(Short code, String value, String detail, Boolean editable) {
        this.code = code;
        this.value = value;
        this.detail = detail;
        this.editable = editable;
    }

    public static LogicOperator_DM getLogicOperatorByCode(Short code){
        for (LogicOperator_DM enu : LogicOperator_DM.values()) {
            if (enu.code.equals(code)) {
                return enu;
            }
        }
        return null;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", this.code.toString());
        map.put("value", this.value);
        map.put("editable", this.editable);
        return map;
    }
}
